package com.kukudexin.time.mayikt.stream;

import com.kukudexin.time.mayikt.entity.UserEntity;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * @author: 酷酷的鑫
 * @Date: 2022/1/12 11:28
 * @description:
 */
public class MinLambdaTest {
    public static void main(String[] args) {
        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity("mayikt", 20));
        userEntities.add(new UserEntity("meite", 28));
        userEntities.add(new UserEntity("zhangsan", 35));
        Optional<UserEntity> min = userEntities.stream().min(new Comparator<UserEntity>() {
            @Override
            public int compare(UserEntity o1, UserEntity o2) {
                return o1.getAge() - o2.getAge();
            }
        });
        System.out.println(min.get());

        boolean result = userEntities.stream().allMatch(new Predicate<UserEntity>() {
            @Override
            public boolean test(UserEntity userEntity) {
                return "mayikt".equals(userEntity.getUserName());
            }
        });
        System.out.println(result);

        boolean res = userEntities.stream().anyMatch(new Predicate<UserEntity>() {
            @Override
            public boolean test(UserEntity userEntity) {
                return "mayikt".equals(userEntity.getUserName());
            }
        });

        boolean res2 = userEntities.stream().anyMatch(userEntity -> "mayikt".equals(userEntity.getUserName()));

    }
}
